<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript" src="js/jquery.js"></script> 
<script type="text/javascript" src="js/highcharts.js"></script>

<title>网络监控</title>
</head>
<body class="container">
<div>
	<table border="3" align="center" cellspacing="0" cellpadding="15px" bgcolor="#77ff55" width="800">
		<thead align="center">
			<tr><th colspan="3" width="80">远程监控</th></tr>
			<tr><th colspan="1" rowspan="2" width="80">实时信息</th><th colspan="2" width="80">灯状态</th></tr>
			<tr>
				<td colspan="1">
					<ol id="led"	style="
							list-style: none;
							display: inline-block;
							padding: 20px 20px;
							border-radius: 40px;
							z-index: 2;">
					</ol>
				</td>
				<td id="status" colspan="1" style="color:red">0.0V</td>
				
				
			</tr>			
			<tr><th colspan="1" width="80">操作</th>
				<th colspan="1"><button style="font-size:20px;" onclick="turn_on();">开灯</button></th>
				<th colspan="1"><button style="font-size:20px;" onclick="turn_off();">关灯</button></th>
				
			</tr>
       			<tr>
             <th colspan="1" width="80">操作</th>
            <th colspan="1"><button style="font-size:20px;" onclick="turn_breath();">呼吸</button></th>
            <th colspan="1"><button style="font-size:20px;" onclick="turn_flash();">闪烁</button></th>
	    


        </tr>
			<tr><th colspan="1" width="80">超声波</th>
				<td id="lightcsb" colspan="1" style="color:blue">实时距离（cm）</td>
				<td id="light" colspan="1" style="color:blue">128lm</td>
			</tr>

		</thead>

	</table>
</div>
<div id="container" style="width:700px;height:400px;margin:0 auto;"></div>
<div style="text-align:center;clear:both;">
<script src="/gg_bd_ad_720x90.js" type="text/javascript"></script>
<script src="/follow.js" type="text/javascript"></script>
</div>






<script type="text/javascript">

$(function () {                                                                     
$(document).ready(function() {                                                  
	Highcharts.setOptions({                                                     
		global: {                                                               
			useUTC: false                                                       
		}                                                                       
	});                                                                         
	
	var ws = new WebSocket('ws://192.168.1.99:8080/');
	ws.onmessage = function(event) {
		var arr=event.data.split(";");		
		document.getElementById("status").innerText=arr[0];
		document.getElementById("light").innerText=arr[1];
		if(arr[0]=="on")document.getElementById("led").style.backgroundColor="#ffff00";
		else document.getElementById("led").style.backgroundColor="#010101";		
	}



																			
	var chart;
	var i=0;
	//var arr=[2.52,2.33,2.35,7.19,3.69,3.5,3,3.3,3.2,3.2,3.5,3.6,3.6,3.0,3.5]; 
	var yy=[];
      
//yy[80]=parseInt(document.getElementById("light").innerText);
                                                       
	$('#container').highcharts({                                                
		chart: {                                                                
			type: 'spline',                                                     
			animation: Highcharts.svg, // don't animate in old IE               
			marginRight: 10,                                                    
			events: {                                                           
				load: function() {                                              
																				
					// set up the updating of the chart each second             
					var series = this.series[0];                                
					setInterval(function() {                                    
						var x = (new Date()).getTime(); // current time         
							
						 
						var	y =parseInt(document.getElementById("light").innerText);//parseFloat(arr[i++]); 
                     
						series.addPoint([x, y], true, true);                    
					}, 1000);                                                   
				}                                                               
			}                                                                   
		},                                                                      
		title: {                                                                
			text: '超声波实时动态走势图--1秒'                                            
		},                                                                      
		xAxis: {                                                                
			type: 'datetime',                                                   
			tickPixelInterval: 100                                              
		},                                                                      
		yAxis: {                                                                
			title: {                                                            
				text: '超声波实时动态走势图--1秒'                                                   
			},                                                                  
			plotLines: [{                                                       
				value: 0,                                                       
				width: 1,                                                       
				color: '#808080'                                                
			}]                                                                  
		},                                                                      
		tooltip: {                                                              
			formatter: function() {                                             
					return '<b>'+ this.series.name +'</b><br/>'+                
					Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
					Highcharts.numberFormat(this.y, 2);                         
			}                                                                   
		},                                                                      
		legend: {                                                               
			enabled: false                                                      
		},                                                                      
		exporting: {                                                            
			enabled: false                                                      
		},                                                                      
		series: [{                                                              
			name: 'csb data',                                                
			data: (function() {                                                 
				// generate an array of random data                             
				var data = [],                                                  
					time = (new Date()).getTime(),                              
					i;                                                          
																				
				for (i = -19; i <= 0; i++) {                                    
					data.push({                                                 
						x: time + i * 1000,                                     
						y: 1                                        
					});                                                         
				}                                                               
				return data;                                                    
			})()                                                                
		}]                                                                      
	});                                                                         
});                                                                             
																				
});     
</script>











<script>
function getXMLHttpRequest()
{
	var xmlhttp = null;
	if(window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
	else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	return xmlhttp;
}
function turn_on()
{
	var kongzhi="on";
	var url="kongzhi2.cgi";
	var xmlHttp = null;
	xmlHttp =  getXMLHttpRequest();
 	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState == 4 && xmlHttp.status==200)
		{
			var ret = xmlHttp.responseText;
			//alert(ret);
			//document.getElementById("status").innerText=ret;
		}
	}
	xmlHttp.open("POST", url, true);
	xmlHttp.send(kongzhi);//将data发送给服务器
}
function turn_off()
{
	var kongzhi="off";
	var url="kongzhi2.cgi";
	var xmlHttp = null;
	xmlHttp =  getXMLHttpRequest();
 	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState == 4 && xmlHttp.status==200)
		{
			var ret = xmlHttp.responseText;
			//alert(ret);
			//document.getElementById("status").innerText=ret;
		}
	}
	xmlHttp.open("POST", url, true);
	xmlHttp.send(kongzhi);//将data发送给服务器
}

function turn_breath()
{
	var kongzhi="breath";
	var url="kongzhi2.cgi";
	var xmlHttp = null;
	xmlHttp =  getXMLHttpRequest();
 	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState == 4 && xmlHttp.status==200)
		{
			var ret = xmlHttp.responseText;
		}
	}
	xmlHttp.open("POST", url, true);
	xmlHttp.send(kongzhi);//将data发送给服务器
}
function turn_flash()
{
	var kongzhi="flash";
	var url="kongzhi2.cgi";
	var xmlHttp = null;
	xmlHttp =  getXMLHttpRequest();
 	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState == 4 && xmlHttp.status==200)
		{
			var ret = xmlHttp.responseText;
		}
	}
	xmlHttp.open("POST", url, true);
	xmlHttp.send(kongzhi);//将data发送给服务器
}


function startTimer(){
    return timer = setInterval(function(){
	myChart.update();
    },5000,myChart);
}
function closeTimer(timer){
    clearInterval(timer)
}

window.onload=function(){
	startTimer();
}

</script>
</body></html>
